#include "stdafx.h"
#include "../vfs/FileStream.h"

namespace ja2{ namespace vfs
{
	FileStreamIterator::FileStreamIterator(FileStream_t *pFile, boost::iostreams::stream_offset Position)
		: m_pFile(pFile), m_Position(Position)
	{
	}

	void FileStreamIterator::increment()
	{
		// Increment position in file
		m_pFile->seekg(1, std::ios_base::cur);
		++m_Position;
		// Get the character
		m_Char = static_cast<char>(m_pFile->peek());
	}

	bool FileStreamIterator::equal(FileStreamIterator const &Right) const
	{
		assert(m_pFile == Right.m_pFile);
		// Positions are equal
		return (m_Position == Right.m_Position);
	}

	char const &FileStreamIterator::dereference() const
	{
		return m_Char;
	}

	FileStreamIterator file_begin(FileStream_t *pFile)
	{
		return FileStreamIterator(pFile, 0);
	}

	FileStreamIterator file_end(FileStream_t *pFile)
	{
		// Go to end
		pFile->seekg(0, std::ios_base::end);
		
		return FileStreamIterator(pFile, pFile->tellg());
	}
} /*vfs*/} /*ja2*/